#
# Copyright 2024 Kumo.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
# below are examples, after initialization, modify it to your own.
###########################################################################
###kmcmake_example


set(kj_sources
        kj/array.cc
        kj/cidr.cc
        kj/list.cc
        kj/common.cc
        kj/debug.cc
        kj/exception.cc
        kj/io.cc
        kj/memory.cc
        kj/mutex.cc
        kj/string.cc
        kj/source-location.cc
        kj/hash.cc
        kj/table.cc
        kj/thread.cc
        kj/main.cc
        kj/arena.cc
        kj/test-helpers.cc
        kj/units.cc
        kj/encoding.cc
        kj/refcount.cc
        kj/string-tree.cc
        kj/time.cc
        kj/filesystem.cc
        kj/filesystem-disk-unix.cc
        kj/filesystem-disk-win32.cc
        kj/parse/char.cc
        kj/async.cc
        kj/async-unix.cc
        kj/async-win32.cc
        kj/async-io-win32.cc
        kj/async-io.cc
        kj/async-io-unix.cc
        kj/timer.cc
        kj/compat/url.cc
        kj/compat/http.cc
        kj/compat/readiness-io.cc
        kj/compat/tls.cc
        kj/compat/gzip.cc
)

set(shark_sources_lite
        c++.sk.cc
        blob.cc
        arena.cc
        layout.cc
        list.cc
        any.cc
        message.cc
        schema.sk.cc
        stream.sk.cc
        serialize.cc
        serialize-packed.cc
        schema.cc
        schema-loader.cc
        dynamic.cc
        stringify.cc
        serialize-async.cc
        capability.cc
        membrane.cc
        dynamic-capability.cc
        rpc.cc
        rpc.sk.cc
        rpc-twoparty.cc
        rpc-twoparty.sk.cc
        persistent.sk.cc
        ez-rpc.cc
        compat/json.cc
        compat/json.sk.cc
        compat/websocket-rpc.cc
)
set(shark_sources ${kj_sources} ${shark_sources_lite})

kmcmake_cc_library(
        NAMESPACE ${PROJECT_NAME}
        NAME shark
        SOURCES
        ${shark_sources}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)

kmcmake_cc_library(
        NAMESPACE ${PROJECT_NAME}
        NAME shark_test
        SOURCES
        kj/test.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        shark::shark_static
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)

set(sharkc_sources
        compiler/type-id.cc
        compiler/error-reporter.cc
        compiler/lexer.sk.cc
        compiler/lexer.cc
        compiler/grammar.sk.cc
        compiler/parser.cc
        compiler/generics.cc
        compiler/node-translator.cc
        compiler/compiler.cc
        schema-parser.cc
        serialize-text.cc
)


kmcmake_cc_library(
        NAMESPACE ${PROJECT_NAME}
        NAME sharkc
        SOURCES
        ${sharkc_sources}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        PLINKS
        shark::shark_static
        ${KMCMAKE_DEPS_LINK}
        PUBLIC
)

kmcmake_cc_binary(
        NAMESPACE ${PROJECT_NAME}
        NAME shark
        SOURCES
        compiler/module-loader.cc
        compiler/shark.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        LINKS
        shark::sharkc_static
        shark::shark_static
        ${KMCMAKE_DEPS_LINK}
        ${KMCMAKE_STATIC_BIN_OPTION}
        PUBLIC
)

set_target_properties(shark PROPERTIES SHARK_INCLUDE_DIRECTORY
        $<JOIN:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..>,$<INSTALL_INTERFACE:${CMAKE_INSTALL_BINDIR}/../include>>
)

kmcmake_cc_binary(
        NAMESPACE ${PROJECT_NAME}
        NAME sharkc-cpp
        SOURCES
        compiler/sharkc-cpp.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        LINKS
        shark::shark_static
        shark::sharkc_static
        ${KMCMAKE_DEPS_LINK}
        ${KMCMAKE_STATIC_BIN_OPTION}
        PUBLIC
)

kmcmake_cc_binary(
        NAMESPACE ${PROJECT_NAME}
        NAME sharkc-sk
        SOURCES
        compiler/sharkc-sk.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        LINKS
        shark::shark_static
        shark::sharkc_static
        ${KMCMAKE_DEPS_LINK}
        ${KMCMAKE_STATIC_BIN_OPTION}
        PUBLIC
)
